package com.baohulu.baohulu.bean;

import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

public class Device {
    private long id;
    private String province;
    private String city;
    private String address;
    private double latitude;
    private double longitude;
    private int type;
    private int capacity;
    private int size;
    private String key;

    private Device(long id, String province, String city, String address,
                   double latitude, double longitude, int type,
                   int capacity, int size, String key) {
        this.id = id;
        this.province = province;
        this.city = city;
        this.address = address;
        this.latitude = latitude;
        this.longitude = longitude;
        this.type = type;
        this.capacity = capacity;
        this.size = size;
        this.key = key;
    }

    public static Device fromJsonObject(JSONObject jsonObject) {
        Device device = null;
        try {
            long id = jsonObject.getLong("id");
            String province = jsonObject.getString("province");
            String city = jsonObject.getString("city");
            String address = jsonObject.getString("address");
            double latitude = jsonObject.getDouble("latitude");
            double longitude = jsonObject.getDouble("longitude");
            int type = jsonObject.getInt("type");
            int capacity = jsonObject.getInt("capacity");
            int size = jsonObject.getInt("size");
            String key = jsonObject.getString("key");
            device = new Device(id, province, city, address, latitude, longitude, type, capacity, size, key);
        } catch (JSONException e) {
            Log.e("Device", "fromJsonObject: ", e);
        }
        return device;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getCapacity() {
        return capacity;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
}
